<template>
  <view>
    <!-- <text>今日:{{ today }}---{{ today.getLunar().getSolar() }}</text> -->

    <uni-card
      title="下一个戊日"
      :extra="nextWuRi.getLunar().getSolar().toString()"
    >
      <view style="text-align: center"
        >还有<span style="color: #eb261a; font-size: 46px">{{ gap }}</span
        >天</view
      >
    </uni-card>
    <!-- <button @click="test()">test</button> -->
    <view style="text-align: center; line-height: 44px; height: 44px">{{
      year + '年戊日表'
    }}</view>
    <uni-table border stripe emptyText="暂无更多数据">
      <!-- 表头行 -->
      <uni-tr>
        <uni-th align="center" width="60px">公历</uni-th>
        <uni-th align="center" width="60px">道历</uni-th>
        <uni-th align="center" width="60px">戊日</uni-th>
      </uni-tr>
      <!-- 表格数据行 -->
      <uni-tr v-for="item in tableData" :key="item.date">
        <uni-td align="center">{{ item.date }}</uni-td>
        <uni-td align="center">{{ item.lunar }}</uni-td>
        <uni-td align="center">{{ item.wuri }}</uni-td>
      </uni-tr>
    </uni-table>
  </view>
</template>

<script>
import { 日历 } from '../../utils/index'
const { Tao, Lunar, LunarUtil, Solar } = require('lunar-javascript')
export default {
  data() {
    let date = new Date()
    return {
      nextWuRi: null,
      gap: null,
      today: null,
      year: date.getFullYear() + ''
    }
  },
  onLoad(option) {
    console.log(this.year, '0000000000')
    let d = Solar.fromDate(new Date())
    this.today = Tao.fromLunar(d.getLunar())
    this.nextWuRi = this.genNextWuRi()
    this.gap = this.nextWuRi
      .getLunar()
      .getSolar()
      .subtract(Solar.fromDate(new Date()))
    console.log(this.nextWuRi.toString())
    console.log(this.nextWuRi.getLunar().toString())
    console.log(this.nextWuRi.getLunar().getSolar().toString())
    console.log(this.gap)
  },
  computed: {
    tableData: function () {
      // console.log(this.year + 'kkkkk')
      return 日历.getWuInYear(this.year)
    }
  },
  methods: {
    genNextWuRi() {
      let today = Solar.fromDate(new Date())
      today = today.next(1)
      let d
      let i = 0
      do {
        d = Tao.fromLunar(today.getLunar())
        today = today.next(1)
        i++
      } while (!d.isDayWu())
      this.gap = i
      return d
    },
    test() {
      // let table =
    }
  }
}
</script>

<style lang="less"></style>
